<template>
  <div class="solutionConfig">
    <van-nav-bar
      :title="$route.meta.title"
      left-arrow
      :border="false"
      @click-left="clickLeft"
      class="nav-bar"
    >
    </van-nav-bar>
    <!-- <van-cell-group>
      <van-cell title="样品编号" />
    </van-cell-group> -->
    <van-cascader
      v-model="cascaderValue"
      title="请选择样品"
      :options="options"
      @close="show = false"
      @finish="onFinish"
    />
  </div>
</template>

<script>
import { Tabbar, TabbarItem, NavBar, Icon, Cell, CellGroup,Notify } from "vant";
const axios = require("axios");
export default {
  name: "solutionConfig",
  components: {
    [Tabbar.name]: Tabbar,
    [TabbarItem.name]: TabbarItem,
    [NavBar.name]: NavBar,
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Notify.name]: Notify,
  },
  data() {
    return {
      options: [],
      cascaderValue: "",
      token: "",
      gDomain: "",
    };
  },
  mounted() {
    this.gDomain = localStorage.getItem("domainKey");
    this.token = localStorage.getItem("tokenKey");
    this.fetchItems();
  },
  methods: {
    clickLeft() {
      this.$router.replace({ name: "home" });
    },
    async fetchItems() {
      var that = this;
      await axios
        .get(
          that.gDomain +
            "/API/QualityTest/GetTestTree?pageModel[Search][]=30&pageModel[Search][]=UrgencyDegree&pageModel[Token]=" +
            that.token
        )
        .then(function (res) {
          var code = res.data.ErrorCode;
          if (code == 0) {
            var result = res.data.Result;
            if (!result || result.length == 0) return false;

            that.dowhile(result);
            that.options = result;
          } else {
            // Notify({ type: "danger", message: res.data.ErrorMsg });
          }
        })
        .catch(() => {});
    },
    dowhile(b) {
      for (var i = 0; i < b.length; i++) {
        b[i].text = b[i].name;
        b[i].value = b[i].code;
        if (b[i].children && b[i].children.length > 0) {
          this.dowhile(b[i].children);
        } else {
          delete b[i].children;
        }
      }
    },
    onFinish({ selectedOptions }) {
      var len = selectedOptions.length;
      var toDetail = selectedOptions[len - 1];
      this.$router.push({ name: "configDetail", params: toDetail });
    },
  },
};
</script>
<style>
.van-nav-bar__title {
  color: #fff;
}
.van-icon-arrow-left {
  color: #fff !important;
}
.van-cell__title {
  text-align: left;
  font-weight: 500;
}
.van-tree-select__item {
  color: #000;
}
.van-tree-select__item--active {
  color: #ee0a24;
}
.van-picker__cancel {
  visibility: hidden;
}
</style>
<style scoped lang="less">
.solutionConfig {
  margin: 0;
  padding: 0;
  color: #000;
}
.nav-bar {
  background-color: #49bbef;
}
</style>